package com.vnp.cooking.adapter;

import java.util.ArrayList;

import com.vnp.cooking.R;
import com.vnp.cooking.adapter.CanhanListAdapter.ViewHolder;
import com.vnp.cooking.bean.ObjAttribute;
import com.vnp.cooking.utils.PreferenceHelper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

public class DetailDacDiemAdapter extends BaseAdapter {

	Context context;
	ArrayList<ObjAttribute> listDetails;
	PreferenceHelper preferenceHelper;

	public DetailDacDiemAdapter(Context context,
			ArrayList<ObjAttribute> listDetails) {
		super();
		this.context = context;
		this.listDetails = listDetails;
		preferenceHelper = new PreferenceHelper(context);
	}

	@Override
	public int getCount() {
		return listDetails.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View v, ViewGroup parent) {
		ViewHolder holder = null;
		if (v == null) {
			LayoutInflater inflater = LayoutInflater.from(context);
			v = inflater.inflate(R.layout.dialog_item, parent, false);
			holder = new ViewHolder();

			holder.txtDetails = (TextView) v.findViewById(R.id.txt_ten_item);
			holder.cbChoose = (ImageView) v.findViewById(R.id.img_selected);

			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		ObjAttribute item = listDetails.get(position);
		
		holder.txtDetails.setText(item.getName());
		if (item.getId() == (preferenceHelper.getIdDacdiem()) ) {
			holder.cbChoose.setVisibility(View.VISIBLE);
		} else {
			holder.cbChoose.setVisibility(View.GONE);
		}
		
		// Animation list
		/*Animation animation = AnimationUtils.loadAnimation(context,R.anim.animation_list_text);
		v.startAnimation(animation);*/
		return v;
	}

	class ViewHolder {
		TextView txtDetails;
		ImageView cbChoose;
	}

}
